package edu.hrbu.spring.bean;

import org.springframework.beans.factory.FactoryBean;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 徐登宇
 */
public class DateFactoryBean implements FactoryBean<Date> {

    private String dateStr;

    public void setDateStr(String dateStr) {
        this.dateStr = dateStr;
    }

    /**
     * 通过工厂bean来加工普通bean
     * @return
     * @throws Exception
     */
    @Override
    public Date getObject() throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.parse(dateStr);
    }

    @Override
    public Class<?> getObjectType() {
        return null;
    }
}
